import { useTtsaStore } from '@/store/ttsa'
import { useConfigStore } from '@/store/config'
import { MODE } from '@/constants/ttsa'

export default function useSub(emit) {

  const ttsa = useTtsaStore()
  const config: any = useConfigStore()

  const onClose = () => {
    if (ttsa.paused && ttsa.mode !== MODE.QA) ttsa.goon()
    emit('unmount')
  }

  onBeforeMount(() => {
    if (config.subscription.interval_type === 2 && config.subscription.interval) {
      setTimeout(onClose, config.subscription.interval * 1000)
    }
  })

  return {
    onClose,
    config
  }
}